package financial.sharing.center.contract.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.contract.model.entity.Contract;
import financial.sharing.center.contract.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


/**
 * @ClassName ContractController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/4/5
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/contract/contract/")
public class ContractController {

    @Autowired
    private ContractService contractServiceImpl;

    @PostMapping(value = "get/all/contract")
    public R selectAllContract(String selectContractName,
                               String selectFirstParty,
                               String selectSecondParty,
                               Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<Contract> result = this.contractServiceImpl.selectAllContract(selectContractName,selectFirstParty,selectSecondParty);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/contract")
    public R createOneContract(String contractName,
                               Integer contractTypeValue,
                               Integer contractDirectionValue,
                               String firstParty,
                               String secondParty){
        Integer result = this.contractServiceImpl.createOneContract(contractName,contractTypeValue,contractDirectionValue,firstParty,secondParty);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/contract")
    public R compileOneContract(@RequestBody Contract contract) throws IOException {
        Integer result = this.contractServiceImpl.compileOneContract(contract);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/contract")
    public R deleteOneContract(Integer id){
        Integer result = this.contractServiceImpl.deleteOneContract(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/list/contract")
    public R getListContract(Integer contractDirectionValue){
        List<Contract> result = this.contractServiceImpl.getListContract(contractDirectionValue);
        return R.ok(result);
    }


}
